import sys
import os.path
import datetime

from selenium import webdriver
from selenium.webdriver.ie.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager

#创建浏览器对象
class Driver:
    driver=""
    def __init__(self):
        options = webdriver.EdgeOptions()
        self.driver = webdriver.Edge(service=Service(EdgeChromiumDriverManager().install()),options=options)
        #添加隐式等待
        self.driver.implicitly_wait(3)
    def getScreeShot(self):
        # 创建屏幕截图
        # 图片文件名称：./2022-04-01-122356.png
        # 图片路径：../images/调用方法-2022-04-01/2022-04-01-122356.png
        # 图片路径：../images/LoginSucTest-2022-04-01/2022-04-01-122356.png
        # 图片路径：../images/LoginFailTest-2022-04-01/2022-04-01-122356.png
        dirname = datetime.datetime.now().strftime("%Y-%m-%d")
        # 判断文件夹是否存在，若不存在 则创建文件夹
        if not os.path.exists("../images/" + dirname):
            os.mkdir("../images/" + dirname)
        filename = sys._getframe().f_back.f_code.co_name + "-" + datetime.datetime.now().strftime(
            "%Y-%m-%d-%H%M%S") + ".png"
        self.driver.save_screenshot("../images/" + dirname + "/" + filename)


ForumDriver = Driver()